﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RotateDemo01
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private DoubleAnimation _rotationAnimation;

        public MainWindow()
        {
            InitializeComponent();
            SetupAnimation();
        }

        private void SetupAnimation()
        {
            _rotationAnimation = new DoubleAnimation
            {
                From = 0,
                To = 360,
                Duration = TimeSpan.FromSeconds(5), // 默认持续时间
                RepeatBehavior = RepeatBehavior.Forever
            };
            buttonRotationTransform.BeginAnimation(RotateTransform.AngleProperty, _rotationAnimation);
        }

        private void SpeedSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            UpdateAnimationDuration();
        }

        private void UpdateAnimationDuration()
        {
            double speed = speedSlider.Value;
            if (_rotationAnimation != null)
            {
                _rotationAnimation.Duration = TimeSpan.FromSeconds(10 / speed); // 反比例关系
                // 重新开始动画以应用新的持续时间
                buttonRotationTransform.BeginAnimation(RotateTransform.AngleProperty, _rotationAnimation);
            }
        }
    }
}